<?php

/**
 * @file   admin.php
 * @date   2017-11-15 15:22:57
 * @author huwhis<huuwhois>
 * @version  0.0.1
 */

namespace app\admin\model;

use think\Model;

class Category extends Model
{
    protected $arr = array();

    public function getCateNamesFP($pid = null)
    {
            return $this->where('pid', $pid)->column('id, name');
    }
    
    public function getIds($pid = 0)
    {
        $ids = $this->where('pid', $pid)->column('id');
        foreach ($ids as $val) {
            $ids = $this->getIds($val);
            $this->arr[] = $val;
        }
        return $this->arr;
    }

    // public function getCateNames($pid = null)
    // {
    //     if ($pid === null) {
    //         return $this->column('id, name');
    //     } else {
    //         return $this->where('pid', $pid)->column('id, name');
    //     }
    // }

    public function getCateName($id)
    {
        return $this->where('id', $id)->value('name');
    }
    
    public function getCateTree()
    {
        $data = $this->where('status', 1)->field('id, pid, name')->select();

        if ($data) {
            $data = collection($data)->toArray();
        }

        return get_tree($data);
    }
}
